cmake_minimum_required(VERSION 3.16)
project(clang_tool_demo LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# 查找 Clang 与 LLVM 包
find_package(Clang REQUIRED CONFIG)
find_package(LLVM REQUIRED CONFIG)

message(STATUS "Using Clang from ${CLANG_INSTALL_PREFIX}")

list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_DIR}")
include(AddLLVM)

add_executable(clang-tool src/Tool.cpp)
target_include_directories(clang-tool PRIVATE
  ${LLVM_INCLUDE_DIRS}
  ${CLANG_INCLUDE_DIRS}
)

target_compile_definitions(clang-tool PRIVATE
  ${LLVM_DEFINITIONS}
)

# 通过 llvm_map_components_to_libnames 获取所需的 LLVM 组件库
llvm_map_components_to_libnames(LLVM_LIBS support option)

target_link_libraries(clang-tool PRIVATE
  clangTooling
  clangBasic
  clangASTMatchers
  clangFrontend
  clangRewrite
  clangLex
  clangParse
  clangSema
  clangAnalysis
  clangAST
  clangDriver
  clangSerialization
  clangEdit
  clangSupport
  ${LLVM_LIBS}
  ${LIB}
)
